package com.java.action;

import java.util.List;

import com.java.service.IDeptService;
import com.opensymphony.xwork2.ActionSupport;
import com.training.pojo.chengshu.UDept;

public class AddDeptAction extends ActionSupport {

	private IDeptService deptService;
	private UDept dept;
	private String msg;

	public String execute() {
		List<UDept> list = deptService.list1();
		String ss = null;
		String s = dept.getDeptname();
		if(s==null||s.equals("")){
			msg="部门名称不能为空";
			ss ="fail";
		}else{
			int flag=0;
			if (list != null) {
				for (UDept d : list) {
					if (s.equals(d.getDeptname())) {
						flag=1;
						
					} 
					
					if(flag==1){
						msg = "部门名称已经存在";
						ss = "fail";
					}else {
						boolean b = deptService.addDept(dept);
						//System.out.println("add成功");
						ss = "success";
					}
				}
			}else{
				boolean b = deptService.addDept(dept);
				//System.out.println("add成功");
				ss = "success";
			}
		}
		return ss;
	}

	public IDeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(IDeptService deptService) {
		this.deptService = deptService;
	}

	public UDept getDept() {
		return dept;
	}

	public void setDept(UDept dept) {
		this.dept = dept;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
